package com.jyxd.web.service.hisview;

import cn.hutool.core.collection.CollectionUtil;
import com.jyxd.web.dao.basic.DrainageTubeRecordDao;
import com.jyxd.web.dao.basic.PrimaryCareDao;
import com.jyxd.web.dao.basic.VitalSignMergeDao;
import com.jyxd.web.dao.patient.PatientDao;
import com.jyxd.web.dao.patient.PatientDiagnosisDao;
import com.jyxd.web.data.basic.DrainageTubeRecord;
import com.jyxd.web.data.basic.NurseRecordForm;
import com.jyxd.web.data.basic.PrimaryCare;
import com.jyxd.web.data.basic.VitalSignMerge;
import com.jyxd.web.data.hisview.*;
import com.jyxd.web.data.patient.Patient;
import com.jyxd.web.data.patient.PatientDiagnosis;
import com.jyxd.web.data.user.User;
import com.jyxd.web.error.JyxdException;
import com.jyxd.web.hisview.*;
import com.jyxd.web.service.hisview.dto.TzbsDto;
import com.jyxd.web.service.user.UserService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

import static com.jyxd.web.util.Base64Util.getId;
import static com.jyxd.web.util.DateUtil.*;
import static com.jyxd.web.util.ExecuteUtil.errorIfEmpty;

@Service
public class HisViewService {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    // 生命体征代码code 呼吸
    private static final String VITAL_SIGN_CODE_BR = "hx";
    // 生命体征温度
    private static final String VITAL_SIGN_CODE_TEMPLATE = "hswd";
    // 生命体征脉搏
    private static final String VITAL_SIGN_CODE_PULSE = "mb";
    // 生命体征心率
    private static final String VITAL_SIGN_CODE_HR = "xl";
    // 生命体征收缩压
    private static final String VITAL_SIGN_CODE_SSY = "xy_ssy";
    // 生命体征舒张压
    private static final String VITAL_SIGN_CODE_SZY = "xy_szy";
    // 生命体征血氧饱和
    private static final String VITAL_SIGN_CODE_SPO2 = "xybhd";

    @Autowired
    private DcHlczjlBzbwhlZdxxDao dcHlczjlBzbwhlZdxxDao;

    @Autowired
    private DcIcuDatBrxxjlkDao dcIcuDatBrxxjlkDao;

    @Autowired
    private DcIcuDatTzjlDao dcIcuDatTzjlDao;

    @Autowired
    private PatientDao patientDao;

    @Autowired
    private VitalSignMergeDao vitalSignMergeDao;

    @Autowired
    private DcIcuDatTzvalueDao dcIcuDatTzvalueDao;

    @Autowired
    private UserService userService;

    @Autowired
    private PatientDiagnosisDao patientDiagnosisDao;

    @Autowired
    private DrainageTubeRecordDao drainageTubeRecordDao;

    @Autowired
    private HisDcHlczjlBzbwhlHlgcDao hisDcHlczjlBzbwhlHlgcDao;

    @Autowired
    private HisDcHlczjlBzbwhlHlczDao hisDcHlczjlBzbwhlHlczDao;

    @Autowired
    private HisDcHlczjlBzbwhlGmsDao HisDcHlczjlBzbwhlGmsDao;

    @Autowired
    private HisDcHlczjlBzbwhlDao hisDcHlczjlBzbwhlDao;

    @Autowired
    private PrimaryCareDao primaryCareDao;


    /**
     * 病重（病危）患者护理 记录_诊断
     *
     * @param patient
     */
    private DcHlczjlBzbwhlZdxx setDcHlczjlBzbwhlZdxx(Patient patient, DcHlczjlBzbwhlZdxx dcHlczjlBzbwhlZdxx) {
        errorIfEmpty(patient, "患者信息不存在");
        if (Objects.isNull(dcHlczjlBzbwhlZdxx))
            dcHlczjlBzbwhlZdxx = new DcHlczjlBzbwhlZdxx();
        dcHlczjlBzbwhlZdxx.setYljgdm("40570021614040211A1001");//医疗机构代码
        dcHlczjlBzbwhlZdxx.setYljgmc("长治医学院附属和平医院");//医疗机构名称
        dcHlczjlBzbwhlZdxx.setYjlxh(patient.getId());//源记录序号
        dcHlczjlBzbwhlZdxx.setZyjlxh(patient.getId());//主表原记录序号
        dcHlczjlBzbwhlZdxx.setYexh("");//婴儿序号 无 设置""
        dcHlczjlBzbwhlZdxx.setJzlsh(patient.getVisitId());//就诊流水号
        dcHlczjlBzbwhlZdxx.setPatid(patient.getAppId());//Patid内码 患者id 与住院号一致
        dcHlczjlBzbwhlZdxx.setJzlb("2"); // 就诊类别（重症为住院患者，所以就诊类别为2）
        dcHlczjlBzbwhlZdxx.setMzh("");// 门诊病历号（住院患者可以为空））
        dcHlczjlBzbwhlZdxx.setZyhm(patient.getAppId());//住院号码
        dcHlczjlBzbwhlZdxx.setHzxm(patient.getName());//患者姓名
        dcHlczjlBzbwhlZdxx.setZdbm(getDiagnosis(patient, "bm"));//疾病诊断编码
        dcHlczjlBzbwhlZdxx.setZdmc(getDiagnosis(patient, "mc"));//疾病诊断名称
        dcHlczjlBzbwhlZdxx.setGxrq(yyyyMMddHHmmssSdfToString(new Date()));//数据更新日期
        dcHlczjlBzbwhlZdxx.setSysId("0");//0：正常，1：删除或作废
        return dcHlczjlBzbwhlZdxx;
    }

   /* public HttpResult getList (Map<String, Object> map) {
        Patient patient = patientDao.queryData((String) map.get("patientId"));
        PrimaryCare primaryCare = primaryCareDao.queryData((String) map.get("primaryCareId"));
        errorIfEmpty(patient, "患者不存在");

        List<VitalSignMerge> vitalSignMerges = vitalSignMergeDao.queryList(map);
        errorIfEmpty(vitalSignMerges, "生命体征数据暂无");
        VitalSignMerge vitalSignMerge = vitalSignMerges.get(0);
        TzbsDto tzbsDto = new TzbsDto((String) map.get("tzdm"), "呼吸", vitalSignMerge.getNursingAssessment(), vitalSignMerge.getBr(), "次/分");
        return new HttpResult(200, hisDcHlczjlBzbwhlHlczDao.insert(setDcHlczjlBzbwhlHlcz(patient, primaryCare)), "请求数据成功");
    }*/

    /**
     * 诊断增改
     * todo 呼吸机暂时未接入
     * @param patient
     */
    public void saveDcHlczjlBzbwhlZdxx(Patient patient) {
        errorIfEmpty(patient, "数据中心护理观察逻辑错误：患者信息不存在");
        Map<String, Object> map = new HashMap<>();
        map.put("yjlxh", patient.getId());
        DcHlczjlBzbwhlZdxx dcHlczjlBzbwhlZdxx = dcHlczjlBzbwhlZdxxDao.queryData(map);
        boolean isNewSave = Objects.isNull(dcHlczjlBzbwhlZdxx) ? true : false;
        dcHlczjlBzbwhlZdxx = setDcHlczjlBzbwhlZdxx(patient, dcHlczjlBzbwhlZdxx);
        if (StringUtils.isEmpty(dcHlczjlBzbwhlZdxx.getZdmc()))
            return;
        if (isNewSave)
            dcHlczjlBzbwhlZdxxDao.insert(dcHlczjlBzbwhlZdxx);
        else
            dcHlczjlBzbwhlZdxxDao.update(dcHlczjlBzbwhlZdxx);
    }




    /**
     * 护理观察增改
     * todo 2
     * @param patient
     * @param object
     */
    public void saveDcHlczjlBzbwhlHlgc(Patient patient, Object object) {
        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            errorIfEmpty(vitalSignMerge, "数据中心护理观察逻辑错误：生命体征信息不存在");
            if (Objects.isNull(patient))
                patient = patientDao.queryData(vitalSignMerge.getPatientId());
            errorIfEmpty(patient, "数据中心护理观察逻辑错误：患者信息不存在");
            Map<String, Object> map = new HashMap<>();
            map.put("yjlxh", vitalSignMerge.getId());
            DcHlczjlBzbwhlHlgc dcHlczjlBzbwhlHlgc = hisDcHlczjlBzbwhlHlgcDao.queryData(map);
            boolean isNewSave = Objects.isNull(dcHlczjlBzbwhlHlgc) ? true : false;
            dcHlczjlBzbwhlHlgc = setDcHlczjlBzbwhlHlgc(patient, object, dcHlczjlBzbwhlHlgc);
            if (StringUtils.isEmpty(dcHlczjlBzbwhlHlgc.getHlgcjg()))
                return;
            if (isNewSave)
                hisDcHlczjlBzbwhlHlgcDao.insert(dcHlczjlBzbwhlHlgc);
            else
                hisDcHlczjlBzbwhlHlgcDao.update(dcHlczjlBzbwhlHlgc);
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            errorIfEmpty(nurseRecordForm, "数据中心护理观察逻辑错误：生命体征信息不存在");
            if (Objects.isNull(patient))
                patient = patientDao.queryData(nurseRecordForm.getPatientId());
            errorIfEmpty(patient, "数据中心护理观察逻辑错误：患者信息不存在");
            Map<String, Object> map = new HashMap<>();
            map.put("yjlxh", nurseRecordForm.getId());
            DcHlczjlBzbwhlHlgc dcHlczjlBzbwhlHlgc = hisDcHlczjlBzbwhlHlgcDao.queryData(map);
            boolean isNewSave = Objects.isNull(dcHlczjlBzbwhlHlgc) ? true : false;
            dcHlczjlBzbwhlHlgc = setDcHlczjlBzbwhlHlgc(patient, object, dcHlczjlBzbwhlHlgc);
            if (StringUtils.isEmpty(dcHlczjlBzbwhlHlgc.getHlgcjg()))
                return;
            if (isNewSave)
                hisDcHlczjlBzbwhlHlgcDao.insert(dcHlczjlBzbwhlHlgc);
            else
                hisDcHlczjlBzbwhlHlgcDao.update(dcHlczjlBzbwhlHlgc);
        }

    }

    /**
     * 赋值出入量记录_护理观察
     *
     * @param patient
     */
    private DcHlczjlBzbwhlHlgc setDcHlczjlBzbwhlHlgc(Patient patient, Object object, DcHlczjlBzbwhlHlgc dcHlczjlBzbwhlHlgc) {
        errorIfEmpty(patient, "患者信息不存在");
        if (Objects.isNull(dcHlczjlBzbwhlHlgc))
            dcHlczjlBzbwhlHlgc = new DcHlczjlBzbwhlHlgc();
        dcHlczjlBzbwhlHlgc.setYljgdm("40570021614040211A1001");//医疗机构代码
        dcHlczjlBzbwhlHlgc.setYljgmc("长治医学院附属和平医院");//医疗机构名称
        dcHlczjlBzbwhlHlgc.setYexh("");//婴儿序号 无 设置""
        dcHlczjlBzbwhlHlgc.setJzlb("2"); // 就诊类别（重症为住院患者，所以就诊类别为2）
        dcHlczjlBzbwhlHlgc.setJzlsh(patient.getVisitId());//就诊流水号
        dcHlczjlBzbwhlHlgc.setPatid(patient.getAppId());//Patid内码 患者id 与住院号一致
        dcHlczjlBzbwhlHlgc.setMzh("");// 门诊病历号（住院患者可以为空））
        dcHlczjlBzbwhlHlgc.setZyhm(patient.getAppId());//住院号码
        dcHlczjlBzbwhlHlgc.setHzxm(patient.getName());//患者姓名
        dcHlczjlBzbwhlHlgc.setHlgcxmmc("生命体征");//护理观察项目名称
        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            dcHlczjlBzbwhlHlgc.setYjlxh(vitalSignMerge.getId());//源记录序号
            dcHlczjlBzbwhlHlgc.setZyjlxh(vitalSignMerge.getId());//主表原记录序号
            dcHlczjlBzbwhlHlgc.setHlgcjg(vitalSignMerge.getNursingAssessment());//护理观察结果
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            dcHlczjlBzbwhlHlgc.setYjlxh(nurseRecordForm.getId());//源记录序号
            dcHlczjlBzbwhlHlgc.setZyjlxh(nurseRecordForm.getId());//主表原记录序号
            dcHlczjlBzbwhlHlgc.setHlgcjg(nurseRecordForm.getNurseMeasure());//护理观察结果
        }

        dcHlczjlBzbwhlHlgc.setGxrq(yyyyMMddHHmmssSdfToString(new Date()));//数据更新日期
        dcHlczjlBzbwhlHlgc.setSysId("0");//0：正常，1：删除或作废
        return dcHlczjlBzbwhlHlgc;
    }

    /**
     * 护理操作增改
     *
     * @param patient
     * @param primaryCare
     */
    public void saveDcHlczjlBzbwhlHlcz(Patient patient, PrimaryCare primaryCare) {
        errorIfEmpty(primaryCare, "数据中心护理观察逻辑错误：护理操作信息不存在");
        if (Objects.isNull(patient))
            patient = patientDao.queryData(primaryCare.getPatientId());
        errorIfEmpty(patient, "数据中心护理操作逻辑错误：患者信息不存在");
        Map<String, Object> map = new HashMap<>();
        map.put("yjlxh", primaryCare.getId());
        DcHlczjlBzbwhlHlcz dcHlczjlBzbwhlHlcz = hisDcHlczjlBzbwhlHlczDao.queryData(map);
        boolean isNewSave = Objects.isNull(dcHlczjlBzbwhlHlcz) ? true : false;
        dcHlczjlBzbwhlHlcz = setDcHlczjlBzbwhlHlcz(patient, primaryCare, dcHlczjlBzbwhlHlcz);
        if (StringUtils.isEmpty(dcHlczjlBzbwhlHlcz.getHlczmc()))
            return;
        if (isNewSave)
            hisDcHlczjlBzbwhlHlczDao.insert(dcHlczjlBzbwhlHlcz);
        else
            hisDcHlczjlBzbwhlHlczDao.update(dcHlczjlBzbwhlHlcz);
    }


    /**
     * 赋值出入量记录_护理操作
     */
    public DcHlczjlBzbwhlHlcz setDcHlczjlBzbwhlHlcz(Patient patient, PrimaryCare primaryCare, DcHlczjlBzbwhlHlcz dcHlczjlBzbwhlHlcz) {
        errorIfEmpty(patient, "患者信息不存在");
        if (Objects.isNull(dcHlczjlBzbwhlHlcz))
            dcHlczjlBzbwhlHlcz = new DcHlczjlBzbwhlHlcz();
        dcHlczjlBzbwhlHlcz.setYljgdm("40570021614040211A1001");//医疗机构代码
        dcHlczjlBzbwhlHlcz.setYljgmc("长治医学院附属和平医院");//医疗机构名称
        dcHlczjlBzbwhlHlcz.setYjlxh(primaryCare.getId());//源记录序号
        dcHlczjlBzbwhlHlcz.setZyjlxh(primaryCare.getId());//主表原记录序号
        dcHlczjlBzbwhlHlcz.setJzlsh(patient.getVisitId());//就诊流水号
        dcHlczjlBzbwhlHlcz.setPatid(patient.getAppId());//Patid内码 患者id 与住院号一致
        dcHlczjlBzbwhlHlcz.setYexh("");//婴儿序号 无 设置""
        dcHlczjlBzbwhlHlcz.setMzh("");// 门诊病历号（住院患者可以为空））
        dcHlczjlBzbwhlHlcz.setZyhm(patient.getAppId());//住院号码
        dcHlczjlBzbwhlHlcz.setHzxm(patient.getName());//患者姓名
        dcHlczjlBzbwhlHlcz.setJzlb("2"); // 就诊类别（重症为住院患者，所以就诊类别为2）
        dcHlczjlBzbwhlHlcz.setHlczxmlmmc(getNursing(primaryCare));// 护理操作项目类目名称
        dcHlczjlBzbwhlHlcz.setHlczmc(getNursing(primaryCare));// 护理操作项目名称
        dcHlczjlBzbwhlHlcz.setHlczjg("已操作");//护理操作结果
        dcHlczjlBzbwhlHlcz.setGxrq(yyyyMMddHHmmssSdfToString(new Date()));//数据更新日期
        dcHlczjlBzbwhlHlcz.setSysId("0");//0：正常，1：删除或作废
        return dcHlczjlBzbwhlHlcz;
    }


    /**
     * 过敏史增改
     *
     * @param patient
     */
    public void saveDcHlczjlBzbwhlGms(Patient patient) {
        errorIfEmpty(patient, "数据中心护理操作逻辑错误：患者信息不存在");
        Map<String, Object> map = new HashMap<>();
        map.put("yjlxh", patient.getId());
        DcHlczjlBzbwhlGms dcHlczjlBzbwhlGms = HisDcHlczjlBzbwhlGmsDao.queryData(map);
        boolean isNewSave = Objects.isNull(dcHlczjlBzbwhlGms) ? true : false;
        dcHlczjlBzbwhlGms = setDcHlczjlBzbwhlGms(patient, dcHlczjlBzbwhlGms);
        if (StringUtils.isEmpty(dcHlczjlBzbwhlGms.getYjlxh()))
            return;
        if (isNewSave)
            HisDcHlczjlBzbwhlGmsDao.insert(dcHlczjlBzbwhlGms);
        else
            HisDcHlczjlBzbwhlGmsDao.update(dcHlczjlBzbwhlGms);
    }


    /**
     * 赋值一般护理记录_过敏史
     *
     * @param patient
     */
    public DcHlczjlBzbwhlGms setDcHlczjlBzbwhlGms(Patient patient, DcHlczjlBzbwhlGms dcHlczjlBzbwhlGms) {
        errorIfEmpty(patient, "患者信息不存在");
        if (Objects.isNull(dcHlczjlBzbwhlGms))
            dcHlczjlBzbwhlGms = new DcHlczjlBzbwhlGms();
        dcHlczjlBzbwhlGms.setYljgdm("40570021614040211A1001");//医疗机构代码
        dcHlczjlBzbwhlGms.setYljgmc("长治医学院附属和平医院");//医疗机构名称
        dcHlczjlBzbwhlGms.setYjlxh(patient.getId());//源记录序号
        dcHlczjlBzbwhlGms.setZyjlxh(patient.getId());//主表原记录序号
        dcHlczjlBzbwhlGms.setYexh("");//婴儿序号 无 设置""
        dcHlczjlBzbwhlGms.setJzlsh(patient.getVisitId());//就诊流水号
        dcHlczjlBzbwhlGms.setPatid(patient.getAppId());//Patid内码 患者id 与住院号一致
        dcHlczjlBzbwhlGms.setJzlb("2"); // 就诊类别（重症为住院患者，所以就诊类别为2）
        dcHlczjlBzbwhlGms.setMzh("");// 门诊病历号（住院患者可以为空））
        dcHlczjlBzbwhlGms.setZyhm(patient.getAppId());//住院号码
        dcHlczjlBzbwhlGms.setHzxm(patient.getName());//患者姓名
        dcHlczjlBzbwhlGms.setGms("");//T过敏史 先为空传
        dcHlczjlBzbwhlGms.setGxrq(yyyyMMddHHmmssSdfToString(new Date()));//数据更新日期
        dcHlczjlBzbwhlGms.setSysId("0");//0：正常，1：删除或作废
        return dcHlczjlBzbwhlGms;
    }


    /**
     * 护理记录增改111111
     *
     * @param patient
     * @param object
     */
    public void saveDcHlczjlBzbwhl(Patient patient, Object object) {
        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            errorIfEmpty(vitalSignMerge, "数据中心护理观察逻辑错误：生命体征信息不存在");
            if (Objects.isNull(patient))
                patient = patientDao.queryData(vitalSignMerge.getPatientId());
            errorIfEmpty(patient, "数据中心护理操作逻辑错误：患者信息不存在");
            Map<String, Object> map = new HashMap<>();
            map.put("yjlxh", vitalSignMerge.getId());
            DcHlczjlBzbwhl dcHlczjlBzbwhl = hisDcHlczjlBzbwhlDao.queryData(map);
            boolean isNewSave = Objects.isNull(dcHlczjlBzbwhl) ? true : false;
            dcHlczjlBzbwhl = setDcHlczjlBzbwhl(patient, object);
            if (isNewSave)
                hisDcHlczjlBzbwhlDao.insert(dcHlczjlBzbwhl);
            else
                hisDcHlczjlBzbwhlDao.update(dcHlczjlBzbwhl);
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            errorIfEmpty(nurseRecordForm, "数据中心护理观察逻辑错误：生命体征信息不存在");
            if (Objects.isNull(patient))
                patient = patientDao.queryData(nurseRecordForm.getPatientId());
            errorIfEmpty(patient, "数据中心护理操作逻辑错误：患者信息不存在");
            Map<String, Object> map = new HashMap<>();
            map.put("yjlxh", nurseRecordForm.getId());
            DcHlczjlBzbwhl dcHlczjlBzbwhl = hisDcHlczjlBzbwhlDao.queryData(map);
            boolean isNewSave = Objects.isNull(dcHlczjlBzbwhl) ? true : false;
            dcHlczjlBzbwhl = setDcHlczjlBzbwhl(patient, object);
            if (isNewSave)
                hisDcHlczjlBzbwhlDao.insert(dcHlczjlBzbwhl);
            else
                hisDcHlczjlBzbwhlDao.update(dcHlczjlBzbwhl);
        }

    }


    /**
     * 赋值病重（病危）患者护理记录11111
     *
     * @param patient
     */
    public DcHlczjlBzbwhl setDcHlczjlBzbwhl(Patient patient, Object object) {

        errorIfEmpty(patient, "患者信息不存在");
        DcHlczjlBzbwhl dcHlczjlBzbwhl = new DcHlczjlBzbwhl();
        dcHlczjlBzbwhl.setYljgdm("40570021614040211A1001");//医疗机构代码
        dcHlczjlBzbwhl.setYljgmc("长治医学院附属和平医院");//医疗机构名称
        dcHlczjlBzbwhl.setJzlsh(patient.getVisitId());//就诊流水号
        dcHlczjlBzbwhl.setPatid(patient.getAppId());//Patid内码 患者id 与住院号一致
        dcHlczjlBzbwhl.setMzh("");//门诊病历号（住院患者可以为空））
        dcHlczjlBzbwhl.setZyhm(patient.getAppId());//住院号码
        dcHlczjlBzbwhl.setYexh("");//婴儿序号 无 设置""
        dcHlczjlBzbwhl.setJzlb("2"); // 就诊类别（重症为住院患者，所以就诊类别为2）
        dcHlczjlBzbwhl.setZzjgdm("");//医疗机构组织机构代码
        dcHlczjlBzbwhl.setZzjgmc("");//医疗机构组织机构名称
        dcHlczjlBzbwhl.setKsdm("068");//科室代码
        dcHlczjlBzbwhl.setKsmc("重症医学科");// 科室名称
        dcHlczjlBzbwhl.setBqdm("196745");// 病区代码
        dcHlczjlBzbwhl.setBqmc("重症医学科护理站");//病区名称
        dcHlczjlBzbwhl.setBfh("100622");//病房号
        dcHlczjlBzbwhl.setBch(patient.getBedCode());//病床号
        dcHlczjlBzbwhl.setXbdm(patient.getSex() + "");//性别代码
        dcHlczjlBzbwhl.setXbmc(patient.getSex() == 1 ? "男" : "女");//性别名称
        dcHlczjlBzbwhl.setHzxm(patient.getName());//患者姓名
        dcHlczjlBzbwhl.setSfzhm(patient.getIdCard());//身份证号
        dcHlczjlBzbwhl.setNls(getNumber(patient.getAge()));//年龄岁
        dcHlczjlBzbwhl.setNly("");//年龄（月） 赋值""
        dcHlczjlBzbwhl.setHldjdm("2");//护理等级代码   默认为2 （重症）
        dcHlczjlBzbwhl.setHldjmc("一级护理");//护理等级名称
        dcHlczjlBzbwhl.setHllxdm("1");//护理类型代码
        dcHlczjlBzbwhl.setHllxmc("基础护理");// 护理类型名称
        dcHlczjlBzbwhl.setTzkg("0");//体重（kg）
        dcHlczjlBzbwhl.setYsqkdm("2");//饮食情况代码
        dcHlczjlBzbwhl.setYsqkmc("一般");//饮食情况名称
        dcHlczjlBzbwhl.setHxjjhxm("");//呼吸机监护项目
        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            dcHlczjlBzbwhl.setYjlxh(vitalSignMerge.getId());//源记录序号
            dcHlczjlBzbwhl.setTw(getNumber(vitalSignMerge.getTemplate()));//体温（℃）
            dcHlczjlBzbwhl.setXl(getNumber(vitalSignMerge.getHr()));//心率
            dcHlczjlBzbwhl.setHxpl(getNumber(vitalSignMerge.getBr()));//呼吸频率（次/min）
            List<String> nbp = splitNbp(vitalSignMerge.getNbp());
            dcHlczjlBzbwhl.setSsy(getNumber(nbp.get(0)));//收缩压
            dcHlczjlBzbwhl.setSzy(getNumber(nbp.get(1)));//舒张压
            dcHlczjlBzbwhl.setXt(getNumber(vitalSignMerge.getBak6()));//血糖
            dcHlczjlBzbwhl.setHsdm(getCzyContent(vitalSignMerge, "dm"));//护士工号
            dcHlczjlBzbwhl.setHsqm(getCzyContent(vitalSignMerge, "mc"));//护士签名
            dcHlczjlBzbwhl.setQmrqsj(yyyyMMddHHmmssSdfToString(vitalSignMerge.getDataTime()));//签名日期时间
            dcHlczjlBzbwhl.setGxrq(yyyyMMddHHmmssSdfToString(vitalSignMerge.getUpdateTime()));//数据更新日期
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            dcHlczjlBzbwhl.setYjlxh(nurseRecordForm.getId());//源记录序号
            dcHlczjlBzbwhl.setTw(getNumber(nurseRecordForm.getTemplate()));//体温（℃）
            dcHlczjlBzbwhl.setXl(getNumber(nurseRecordForm.getHr()));//心率
            dcHlczjlBzbwhl.setHxpl(getNumber(nurseRecordForm.getBr()));//呼吸频率（次/min）
            List<String> nbp = splitNbp(nurseRecordForm.getNbp());
            dcHlczjlBzbwhl.setSsy(getNumber(nbp.get(0)));//收缩压
            dcHlczjlBzbwhl.setSzy(getNumber(nbp.get(1)));//舒张压
            dcHlczjlBzbwhl.setXt(getNumber(nurseRecordForm.getBloodGlucose()));//血糖
            dcHlczjlBzbwhl.setHsdm(getNurseRecordFormContent(nurseRecordForm, "dm"));//护士工号
            dcHlczjlBzbwhl.setHsqm(getNurseRecordFormContent(nurseRecordForm, "mc"));//护士签名
            dcHlczjlBzbwhl.setQmrqsj(yyyyMMddHHmmssSdfToString(nurseRecordForm.getDataTime()));//签名日期时间
            dcHlczjlBzbwhl.setGxrq(yyyyMMddHHmmssSdfToString(nurseRecordForm.getUpdateTime()));//数据更新日期
        }

        dcHlczjlBzbwhl.setSysId("0");//0：正常，1：删除或作废
        return dcHlczjlBzbwhl;
    }

    /**
     * 新增生命体征记录表和记录值  1111111111111111
     *
     * @param patient
     * @param object
     */
    public void saveDcIcuDatTzjlOrDcIcuDatTzvalue(Patient patient, Object object) {

        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            errorIfEmpty(vitalSignMerge, "生命体征记录表详情逻辑出错：生命体征表不存在");
            if (Objects.isNull(patient))
                patient = patientDao.queryData(vitalSignMerge.getPatientId());
            errorIfEmpty(patient, "生命体征记录表逻辑错误：患者不存在");
            Map<String, Object> map = new HashMap<>();
            map.put("jzlsh", patient.getVisitId());
            map.put("yjlxh", vitalSignMerge.getId());
            Long lsnid = getId();
            DcIcuDatTzjl dcIcuDatTzjl = dcIcuDatTzjlDao.queryData(map);
            boolean isNewSave = Objects.isNull(dcIcuDatTzjl) ? true : false;
            dcIcuDatTzjl = setDcIcuDatTzjl(patient, object, dcIcuDatTzjl, lsnid.toString());
            if (isNewSave)
                dcIcuDatTzjlDao.insert(dcIcuDatTzjl);
            else
                dcIcuDatTzjlDao.update(dcIcuDatTzjl);
            // 继续新增生命体征明细
            dcIcuDatTzvalueList(patient, object, lsnid.toString());
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            errorIfEmpty(nurseRecordForm, "生命体征记录表详情逻辑出错：生命体征表不存在");
            if (Objects.isNull(patient))
                patient = patientDao.queryData(nurseRecordForm.getPatientId());
            errorIfEmpty(patient, "生命体征记录表逻辑错误：患者不存在");
            Map<String, Object> map = new HashMap<>();
            map.put("jzlsh", patient.getVisitId());
            map.put("yjlxh", nurseRecordForm.getId());
            Long lsnid = getId();
            DcIcuDatTzjl dcIcuDatTzjl = dcIcuDatTzjlDao.queryData(map);
            boolean isNewSave = Objects.isNull(dcIcuDatTzjl) ? true : false;
            dcIcuDatTzjl = setDcIcuDatTzjl(patient, object, dcIcuDatTzjl, lsnid.toString());
            if (isNewSave)
                dcIcuDatTzjlDao.insert(dcIcuDatTzjl);
            else
                dcIcuDatTzjlDao.update(dcIcuDatTzjl);
            // 继续新增生命体征明细
            dcIcuDatTzvalueList(patient, object, lsnid.toString());
        }

    }

    /**
     * 新增或修改多个生命体征明细
     *
     * @param patient
     * @param object
     * @param lsnid
     */
    private void dcIcuDatTzvalueList(Patient patient, Object object, String lsnid) {
        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            if (StringUtils.isNotEmpty(vitalSignMerge.getBr()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_BR, patient, object, lsnid);
            if (StringUtils.isNotEmpty(vitalSignMerge.getTemplate()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_TEMPLATE, patient, object, lsnid);
            if (StringUtils.isNotEmpty(vitalSignMerge.getPulse()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_PULSE, patient, object, lsnid);
            if (StringUtils.isNotEmpty(vitalSignMerge.getHr()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_HR, patient, object, lsnid);
            if (StringUtils.isNotEmpty(vitalSignMerge.getSpO2()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_SPO2, patient, object, lsnid);
            if (StringUtils.isEmpty(vitalSignMerge.getNbp()))
                return;
            saveDcIcuDatTzvalue(VITAL_SIGN_CODE_SSY, patient, object, lsnid);
            saveDcIcuDatTzvalue(VITAL_SIGN_CODE_SZY, patient, object, lsnid);
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            if (StringUtils.isNotEmpty(nurseRecordForm.getBr()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_BR, patient, object, lsnid);
            if (StringUtils.isNotEmpty(nurseRecordForm.getTemplate()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_TEMPLATE, patient, object, lsnid);
            if (StringUtils.isNotEmpty(nurseRecordForm.getPulse()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_PULSE, patient, object, lsnid);
            if (StringUtils.isNotEmpty(nurseRecordForm.getHr()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_HR, patient, object, lsnid);
            if (StringUtils.isNotEmpty(nurseRecordForm.getSpO2()))
                saveDcIcuDatTzvalue(VITAL_SIGN_CODE_SPO2, patient, object, lsnid);
            if (StringUtils.isEmpty(nurseRecordForm.getNbp()))
                return;
            saveDcIcuDatTzvalue(VITAL_SIGN_CODE_SSY, patient, object, lsnid);
            saveDcIcuDatTzvalue(VITAL_SIGN_CODE_SZY, patient, object, lsnid);
        }

    }

    /**
     * 新增或修改单个生命体征明细
     *
     * @param patient
     * @param object
     * @param lsnid
     */
    private void saveDcIcuDatTzvalue(String tzdm, Patient patient, Object object, String lsnid) {

        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            TzbsDto tzbsDto = getTzbsDto(tzdm, object);
            if (Objects.isNull(tzbsDto)) // 体征数据不存在不进行保存或修改
                return;
            Map<String, Object> map = new HashMap<>();
            map.put("tzdm", tzbsDto.getTzdm());
            map.put("yjlmxxh", vitalSignMerge.getId());
            DcIcuDatTzvalue dcIcuDatTzvalue = dcIcuDatTzvalueDao.queryData(map);
            boolean isNewSave = Objects.isNull(dcIcuDatTzvalue) ? true : false;
            dcIcuDatTzvalue = setDcIcuDatTzvalue(patient, object, dcIcuDatTzvalue, tzbsDto, lsnid);
            if (isNewSave)
                dcIcuDatTzvalueDao.insert(dcIcuDatTzvalue);
            else
                dcIcuDatTzvalueDao.update(dcIcuDatTzvalue);
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            TzbsDto tzbsDto = getTzbsDto(tzdm, object);
            if (Objects.isNull(tzbsDto)) // 体征数据不存在不进行保存或修改
                return;
            Map<String, Object> map = new HashMap<>();
            map.put("tzdm", tzbsDto.getTzdm());
            map.put("yjlmxxh", nurseRecordForm.getId());
            DcIcuDatTzvalue dcIcuDatTzvalue = dcIcuDatTzvalueDao.queryData(map);
            boolean isNewSave = Objects.isNull(dcIcuDatTzvalue) ? true : false;
            dcIcuDatTzvalue = setDcIcuDatTzvalue(patient, object, dcIcuDatTzvalue, tzbsDto, lsnid);
            if (isNewSave)
                dcIcuDatTzvalueDao.insert(dcIcuDatTzvalue);
            else
                dcIcuDatTzvalueDao.update(dcIcuDatTzvalue);
        }


    }

    /**
     * 体征明细值获取
     *
     * @param tzdm
     * @param object
     * @return
     */
    private TzbsDto getTzbsDto(String tzdm, Object object) {
        if (StringUtils.isEmpty(tzdm))
            return null;

        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            String tzvalueText = getTzvalueText(tzdm, object);
            String blood = getBlood(tzdm, vitalSignMerge);
            switch (tzdm) {
                case VITAL_SIGN_CODE_BR:
                    return new TzbsDto(tzdm, "呼吸", tzvalueText, vitalSignMerge.getBr(), "次/分");
                case VITAL_SIGN_CODE_TEMPLATE:
                    return new TzbsDto(tzdm, "核实温度", tzvalueText, vitalSignMerge.getTemplate(), "℃");
                case VITAL_SIGN_CODE_PULSE:
                    return new TzbsDto(tzdm, "脉搏", tzvalueText, vitalSignMerge.getPulse(), "次/分");
                case VITAL_SIGN_CODE_HR:
                    return new TzbsDto(tzdm, "心率", tzvalueText, vitalSignMerge.getHr(), "次/分");
                case VITAL_SIGN_CODE_SSY:
                    if (StringUtils.isEmpty(blood))
                        return null;
                    return new TzbsDto(tzdm, "血压（收缩压）", tzvalueText, blood, "mmHg");
                case VITAL_SIGN_CODE_SZY:
                    if (StringUtils.isEmpty(blood))
                        return null;
                    return new TzbsDto(tzdm, "血压（舒张压）", tzvalueText, blood, "mmHg");
                case VITAL_SIGN_CODE_SPO2:
                    return new TzbsDto(tzdm, "血氧饱和度", tzvalueText, vitalSignMerge.getSpO2(), "%");
                default:
                    logger.error("不支持的体征明细");
                    return null;
            }
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            String tzvalueText = getTzvalueText(tzdm, object);
            String blood = getBlood3(tzdm, nurseRecordForm);
            switch (tzdm) {
                case VITAL_SIGN_CODE_BR:
                    return new TzbsDto(tzdm, "呼吸", tzvalueText, nurseRecordForm.getBr(), "次/分");
                case VITAL_SIGN_CODE_TEMPLATE:
                    return new TzbsDto(tzdm, "核实温度", tzvalueText, nurseRecordForm.getTemplate(), "℃");
                case VITAL_SIGN_CODE_PULSE:
                    return new TzbsDto(tzdm, "脉搏", tzvalueText, nurseRecordForm.getPulse(), "次/分");
                case VITAL_SIGN_CODE_HR:
                    return new TzbsDto(tzdm, "心率", tzvalueText, nurseRecordForm.getHr(), "次/分");
                case VITAL_SIGN_CODE_SSY:
                    if (StringUtils.isEmpty(blood))
                        return null;
                    return new TzbsDto(tzdm, "血压（收缩压）", tzvalueText, blood, "mmHg");
                case VITAL_SIGN_CODE_SZY:
                    if (StringUtils.isEmpty(blood))
                        return null;
                    return new TzbsDto(tzdm, "血压（舒张压）", tzvalueText, blood, "mmHg");
                case VITAL_SIGN_CODE_SPO2:
                    return new TzbsDto(tzdm, "血氧饱和度", tzvalueText, nurseRecordForm.getSpO2(), "%");
                default:
                    logger.error("不支持的体征明细");
                    return null;
            }
        }else {
            return null;
        }



    }

    /**
     * 获取体征描述
     *
     * @param tzdm
     * @param object
     * @return
     */
    private String getTzvalueText(String tzdm, Object object) {
        if (StringUtils.isEmpty(tzdm))
            return null;
        String blood;

        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            switch (tzdm) {
                case VITAL_SIGN_CODE_BR:
                    return yyyyMMddHHmmSdfToString(vitalSignMerge.getDataTime()) + "的呼吸为：" + vitalSignMerge.getBr() + "(次/分)";
                case VITAL_SIGN_CODE_TEMPLATE:
                    return yyyyMMddHHmmSdfToString(vitalSignMerge.getDataTime()) + "的体温为：" + vitalSignMerge.getTemplate() + "(℃)";
                case VITAL_SIGN_CODE_PULSE:
                    return yyyyMMddHHmmSdfToString(vitalSignMerge.getDataTime()) + "的脉搏为：" + vitalSignMerge.getPulse() + "(次/分)";
                case VITAL_SIGN_CODE_HR:
                    return yyyyMMddHHmmSdfToString(vitalSignMerge.getDataTime()) + "的心率为：" + vitalSignMerge.getHr() + "(次/分)";
                case VITAL_SIGN_CODE_SSY:
                    blood = getBlood(VITAL_SIGN_CODE_SSY, vitalSignMerge);
                    if (StringUtils.isEmpty(blood))
                        return null;
                    return yyyyMMddHHmmSdfToString(vitalSignMerge.getDataTime()) + "的收缩压为：" + blood + "(mmHg)";
                case VITAL_SIGN_CODE_SZY:
                    blood = getBlood(VITAL_SIGN_CODE_SZY, vitalSignMerge);
                    if (StringUtils.isEmpty(blood))
                        return null;
                    return yyyyMMddHHmmSdfToString(vitalSignMerge.getDataTime()) + "的舒张压为：" + blood + "(mmHg)";
                case VITAL_SIGN_CODE_SPO2:
                    return yyyyMMddHHmmSdfToString(vitalSignMerge.getDataTime()) + "的血氧饱和度为：" + vitalSignMerge.getSpO2() + "(%)";
                default:
                    logger.error("不支持的体征明细");
                    return null;
            }
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            switch (tzdm) {
                case VITAL_SIGN_CODE_BR:
                    return yyyyMMddHHmmSdfToString(nurseRecordForm.getDataTime()) + "的呼吸为：" + nurseRecordForm.getBr() + "(次/分)";
                case VITAL_SIGN_CODE_TEMPLATE:
                    return yyyyMMddHHmmSdfToString(nurseRecordForm.getDataTime()) + "的体温为：" + nurseRecordForm.getTemplate() + "(℃)";
                case VITAL_SIGN_CODE_PULSE:
                    return yyyyMMddHHmmSdfToString(nurseRecordForm.getDataTime()) + "的脉搏为：" + nurseRecordForm.getPulse() + "(次/分)";
                case VITAL_SIGN_CODE_HR:
                    return yyyyMMddHHmmSdfToString(nurseRecordForm.getDataTime()) + "的心率为：" + nurseRecordForm.getHr() + "(次/分)";
                case VITAL_SIGN_CODE_SSY:
                    blood = getBlood3(VITAL_SIGN_CODE_SSY, nurseRecordForm);
                    if (StringUtils.isEmpty(blood))
                        return null;
                    return yyyyMMddHHmmSdfToString(nurseRecordForm.getDataTime()) + "的收缩压为：" + blood + "(mmHg)";
                case VITAL_SIGN_CODE_SZY:
                    blood = getBlood3(VITAL_SIGN_CODE_SZY, nurseRecordForm);
                    if (StringUtils.isEmpty(blood))
                        return null;
                    return yyyyMMddHHmmSdfToString(nurseRecordForm.getDataTime()) + "的舒张压为：" + blood + "(mmHg)";
                case VITAL_SIGN_CODE_SPO2:
                    return yyyyMMddHHmmSdfToString(nurseRecordForm.getDataTime()) + "的血氧饱和度为：" + nurseRecordForm.getSpO2() + "(%)";
                default:
                    logger.error("不支持的体征明细");
                    return null;
            }
        }else{
            return null;
        }

    }

    /**
     * 获取血压数据
     *
     * @param tzdm
     * @param vitalSignMerge
     * @return
     */
    private String getBlood(String tzdm, VitalSignMerge vitalSignMerge) {
        if (StringUtils.isEmpty(tzdm))
            return null;
        if (Objects.isNull(vitalSignMerge))
            return null;
        if (StringUtils.isEmpty(vitalSignMerge.getNbp()))
            return null;
        String[] split = StringUtils.split(vitalSignMerge.getNbp(), "/");
        if (split.length < 2)
            return null;
        if (StringUtils.equals(tzdm, VITAL_SIGN_CODE_SSY))
            return split[0];
        if (StringUtils.equals(tzdm, VITAL_SIGN_CODE_SZY))
            return split[1];
        return null;
    }

    /**
     * 获取血压数据(3表合一)
     *
     * @param tzdm
     * @param nurseRecordForm
     * @return
     */
    private String getBlood3(String tzdm, NurseRecordForm nurseRecordForm) {
        if (StringUtils.isEmpty(tzdm))
            return null;
        if (Objects.isNull(nurseRecordForm))
            return null;
        if (StringUtils.isEmpty(nurseRecordForm.getNbp()))
            return null;
        String[] split = StringUtils.split(nurseRecordForm.getNbp(), "/");
        if (split.length < 2)
            return null;
        if (StringUtils.equals(tzdm, VITAL_SIGN_CODE_SSY))
            return split[0];
        if (StringUtils.equals(tzdm, VITAL_SIGN_CODE_SZY))
            return split[1];
        return null;
    }


    /**
     * 体征记录主表
     *
     * @param patient
     * @param object
     * @param dcIcuDatTzjl
     * @return
     */
    private DcIcuDatTzjl setDcIcuDatTzjl(Patient patient, Object object,
                                         DcIcuDatTzjl dcIcuDatTzjl, String lsnid) {
        errorIfEmpty(patient, "患者信息不存在");
        if (Objects.isNull(dcIcuDatTzjl))
            dcIcuDatTzjl = new DcIcuDatTzjl();
        dcIcuDatTzjl.setJzlsh(patient.getVisitId()); // 赋值就诊流水号
        dcIcuDatTzjl.setYljgdm("40570021614040211A1001"); // 医院代码
        dcIcuDatTzjl.setYljgmc("长治医学院附属和平医院"); // 医院名称
        dcIcuDatTzjl.setJzlb("2"); // 就诊类别
        dcIcuDatTzjl.setZyhm(patient.getAppId()); // 住院号码
        dcIcuDatTzjl.setMzh("");  // 门诊号（住院患者门诊号可以为空）
        dcIcuDatTzjl.setPatid(patient.getAppId()); // 患者id
        dcIcuDatTzjl.setHzxm(patient.getName());
        dcIcuDatTzjl.setYexh("");
        dcIcuDatTzjl.setZyrq(yyyyMMddHHmmssSdfToString(new Date())); // 在院日期
        dcIcuDatTzjl.setShczydm("");  // 审核员代码
        dcIcuDatTzjl.setShczymc("");  // 审核员名称
        dcIcuDatTzjl.setShrq("");     // 审核日期
        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            dcIcuDatTzjl.setYjlxh(vitalSignMerge.getId());
            dcIcuDatTzjl.setJlrq(yyyyMMddHHmmssSdfToString(vitalSignMerge.getDataTime()));
            dcIcuDatTzjl.setCzydm(getCzyContent(vitalSignMerge, "dm"));  // 操作员代码
            dcIcuDatTzjl.setCzymc(getCzyContent(vitalSignMerge, "mc"));  // 操作员名称
            dcIcuDatTzjl.setTzjlzt(getTzjlzt(vitalSignMerge));   // 体征记录状态  0 录入状态  1 提交状态 4 逻辑删除
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            dcIcuDatTzjl.setYjlxh(nurseRecordForm.getId());
            dcIcuDatTzjl.setJlrq(yyyyMMddHHmmssSdfToString(nurseRecordForm.getDataTime()));
            dcIcuDatTzjl.setCzydm(getNurseRecordFormContent(nurseRecordForm, "dm"));  // 操作员代码
            dcIcuDatTzjl.setCzymc(getNurseRecordFormContent(nurseRecordForm, "mc"));  // 操作员名称
            dcIcuDatTzjl.setTzjlzt(getTzjlzt3(nurseRecordForm));   // 体征记录状态  0 录入状态  1 提交状态 4 逻辑删除
        }

        dcIcuDatTzjl.setRyts(getRyts(patient));  // 获取入院天数
        dcIcuDatTzjl.setShts("");
        dcIcuDatTzjl.setBszd("smtz");
        dcIcuDatTzjl.setGxrqtimestr(yyyyMMddHHmmssSdfToString(new Date()));
        dcIcuDatTzjl.setGxrq(yyyyMMddHHmmssSdfToString(new Date()));
        dcIcuDatTzjl.setSysId("0");
        dcIcuDatTzjl.setLsnid(lsnid);
        return dcIcuDatTzjl;
    }

    /**
     * 体征记录体征结果值
     *
     * @return
     */
    private DcIcuDatTzvalue setDcIcuDatTzvalue(Patient patient, Object object,
                                               DcIcuDatTzvalue dcIcuDatTzvalue, TzbsDto tzbsDto, String lsnid) {
        if(object instanceof VitalSignMerge){
            VitalSignMerge vitalSignMerge = (VitalSignMerge) object;
            errorIfEmpty(vitalSignMerge, "生命明细，生命体征值不存在");
            if (Objects.isNull(patient))
                patient = patientDao.queryData(vitalSignMerge.getPatientId());
            errorIfEmpty(patient, "具体体征值明细,患者信息不存在");
            errorIfEmpty(tzbsDto, "具体体征值不存在，体征记录明细值失败");
            if (Objects.isNull(dcIcuDatTzvalue))
                dcIcuDatTzvalue = new DcIcuDatTzvalue();
            dcIcuDatTzvalue.setJzlsh(patient.getVisitId()); // 赋值就诊流水号
            dcIcuDatTzvalue.setYljgdm("40570021614040211A1001"); // 医院代码
            dcIcuDatTzvalue.setYljgmc("长治医学院附属和平医院"); // 医院名称
            dcIcuDatTzvalue.setJzlb("2"); // 就诊类别
            dcIcuDatTzvalue.setYjlxh(vitalSignMerge.getId()); // 体征记录在源 系统中的唯一 序号
            dcIcuDatTzvalue.setZyhm(patient.getAppId());
            dcIcuDatTzvalue.setMzh("");
            dcIcuDatTzvalue.setPatid(patient.getAppId());
            dcIcuDatTzvalue.setHzxm(patient.getName());
            dcIcuDatTzvalue.setYjlmxxh(vitalSignMerge.getId());   // 原系统记录明细表
            dcIcuDatTzvalue.setLrrq(yyyyMMddHHmmssSdfToString(vitalSignMerge.getDataTime()));
            dcIcuDatTzvalue.setCjrq(yyyyMMddHHmmssSdfToString(vitalSignMerge.getDataTime()));
            dcIcuDatTzvalue.setSj(hhmmssSdfToString(vitalSignMerge.getDataTime()));
            dcIcuDatTzvalue.setZyrdm(getCzyContent(vitalSignMerge, "dm"));
            dcIcuDatTzvalue.setZyrmc(getCzyContent(vitalSignMerge, "mc"));
            dcIcuDatTzvalue.setTzdm(tzbsDto.getTzdm());
            dcIcuDatTzvalue.setTzmc(tzbsDto.getTzmc());
            dcIcuDatTzvalue.setTzvalueText(tzbsDto.getTzvalueText());
            dcIcuDatTzvalue.setTzvalueNumeric(tzbsDto.getTzvalueNumeric());
            dcIcuDatTzvalue.setTzdw(tzbsDto.getTzdw());
            dcIcuDatTzvalue.setBszd("smtz");
            dcIcuDatTzvalue.setGxrq(yyyyMMddHHmmssSdfToString(new Date()));
            dcIcuDatTzvalue.setSysId("0");
            dcIcuDatTzvalue.setLsnid(lsnid);
        }else if(object instanceof NurseRecordForm){
            NurseRecordForm nurseRecordForm = (NurseRecordForm) object;
            errorIfEmpty(nurseRecordForm, "生命明细，生命体征值不存在");
            if (Objects.isNull(patient))
                patient = patientDao.queryData(nurseRecordForm.getPatientId());
            errorIfEmpty(patient, "具体体征值明细,患者信息不存在");
            errorIfEmpty(tzbsDto, "具体体征值不存在，体征记录明细值失败");
            if (Objects.isNull(dcIcuDatTzvalue))
                dcIcuDatTzvalue = new DcIcuDatTzvalue();
            dcIcuDatTzvalue.setJzlsh(patient.getVisitId()); // 赋值就诊流水号
            dcIcuDatTzvalue.setYljgdm("40570021614040211A1001"); // 医院代码
            dcIcuDatTzvalue.setYljgmc("长治医学院附属和平医院"); // 医院名称
            dcIcuDatTzvalue.setJzlb("2"); // 就诊类别
            dcIcuDatTzvalue.setYjlxh(nurseRecordForm.getId()); // 体征记录在源 系统中的唯一 序号
            dcIcuDatTzvalue.setZyhm(patient.getAppId());
            dcIcuDatTzvalue.setMzh("");
            dcIcuDatTzvalue.setPatid(patient.getAppId());
            dcIcuDatTzvalue.setHzxm(patient.getName());
            dcIcuDatTzvalue.setYjlmxxh(nurseRecordForm.getId());   // 原系统记录明细表
            dcIcuDatTzvalue.setLrrq(yyyyMMddHHmmssSdfToString(nurseRecordForm.getDataTime()));
            dcIcuDatTzvalue.setCjrq(yyyyMMddHHmmssSdfToString(nurseRecordForm.getDataTime()));
            dcIcuDatTzvalue.setSj(hhmmssSdfToString(nurseRecordForm.getDataTime()));
            dcIcuDatTzvalue.setZyrdm(getNurseRecordFormContent(nurseRecordForm, "dm"));
            dcIcuDatTzvalue.setZyrmc(getNurseRecordFormContent(nurseRecordForm, "mc"));
            dcIcuDatTzvalue.setTzdm(tzbsDto.getTzdm());
            dcIcuDatTzvalue.setTzmc(tzbsDto.getTzmc());
            dcIcuDatTzvalue.setTzvalueText(tzbsDto.getTzvalueText());
            dcIcuDatTzvalue.setTzvalueNumeric(tzbsDto.getTzvalueNumeric());
            dcIcuDatTzvalue.setTzdw(tzbsDto.getTzdw());
            dcIcuDatTzvalue.setBszd("smtz");
            dcIcuDatTzvalue.setGxrq(yyyyMMddHHmmssSdfToString(new Date()));
            dcIcuDatTzvalue.setSysId("0");
            dcIcuDatTzvalue.setLsnid(lsnid);
        }

        return dcIcuDatTzvalue;
    }

    /**
     * 判断传入的数据是否为空字符串或null 如果是就赋值为0
     *
     * @param info
     * @return
     */
    private String getNumber(String info) {
        String number = "0";
        if (info != null && info.length() > 0) {
            number = info;
        }
        return number;
    }

    /**
     * 根据护理措施的id查询护理措施内容
     *
     * @param
     * @return
     */
    private String getNursing(PrimaryCare primaryCare) {
        if (Objects.isNull(primaryCare))
            throw new JyxdException("基础数据为空");
        StringBuffer nursingInfo = new StringBuffer();
        if (primaryCare.getOral() != null && primaryCare.getOral().equals("1")) {
            nursingInfo.append("+口腔护理");
        }
        if (primaryCare.getUrethral() != null && primaryCare.getUrethral().equals("1")) {
            nursingInfo.append("+尿道口护理");
        }
        if (primaryCare.getMorningcare() != null && primaryCare.getMorningcare().equals("1")) {
            nursingInfo.append("+晨间护理");
        }
        if (primaryCare.getNightcare() != null && primaryCare.getNightcare().equals("1")) {
            nursingInfo.append("+夜间护理");
        }
        if (primaryCare.getRollOver() != null) {
            nursingInfo.append("+").append(primaryCare.getRollOver());
        }
        if (primaryCare.getTakeBack() != null && primaryCare.getTakeBack().equals("1")) {
            nursingInfo.append("+拍背");
        }
        if (primaryCare.getMassage() != null && primaryCare.getMassage().equals("1")) {
            nursingInfo.append("+按摩");
        }
        if (primaryCare.getNasalFeeding() != null && primaryCare.getNasalFeeding().equals("1")) {
            nursingInfo.append("+鼻饲");
        }
        if (primaryCare.getWetPhlegm() != null && primaryCare.getWetPhlegm().equals("1")) {
            nursingInfo.append("+湿化吸痰");
        }
        if (primaryCare.getRowCharacter() != null && primaryCare.getRowCharacter().equals("1")) {
            nursingInfo.append("+振动排痰");
        }
        if (primaryCare.getAtomizationInhalation() != null && primaryCare.getAtomizationInhalation().equals("1")) {
            nursingInfo.append("+雾化吸入");
        }
        if (primaryCare.getBlanketIceCap() != null) {
            nursingInfo.append("+").append(primaryCare.getBlanketIceCap());
        }
        if (primaryCare.getSkin() != null && primaryCare.getSkin().equals("1")) {
            nursingInfo.append("+皮肤护理");
        }
        if (primaryCare.getLowerLimbsCure() != null) {
            nursingInfo.append("+").append(primaryCare.getLowerLimbsCure());
        }
        String nursingInfoStr = nursingInfo.toString();
        if (StringUtils.isNotEmpty(nursingInfoStr) && nursingInfoStr.substring(0, 1).equals("+")) {
            nursingInfoStr = nursingInfoStr.substring(1, nursingInfo.length());
        }
        return nursingInfoStr;

    }

    /**
     * 获取诊断信息
     *
     * @param patient
     * @param flag
     * @return
     */
    private String getDiagnosis(Patient patient, String flag) {
        boolean isFlag = StringUtils.equals(flag, "mc") ? true : false;
        if (StringUtils.isNotEmpty(patient.getDiagnosisName()))
            return isFlag ? patient.getDiagnosisName() : patient.getDepartmentCode();
        PatientDiagnosis patientDiagnosis = patientDiagnosisDao.queryDataByPatientId(patient.getId());
        if (Objects.isNull(patientDiagnosis) || StringUtils.isEmpty(patientDiagnosis.getDiagnosisName()))
            return null;
        return isFlag ? patientDiagnosis.getDiagnosisName() : patientDiagnosis.getDiagnosisDocCode();
    }


    /**
     * 获取住院天数
     *
     * @param patient
     * @return
     */
    private String getRyts(Patient patient) {
        if (Objects.isNull(patient))
            return "0";
        if (Objects.isNull(patient.getVisitTime()))
            return "0";
        Long time = new Date().getTime() - patient.getVisitTime().getTime();
        return "" + time / 1000 / 60 / 60 / 24;
    }

    /**
     * 获取体征记录状态
     *
     * @param vitalSignMerge
     * @return
     */
    private String getTzjlzt(VitalSignMerge vitalSignMerge) {
        if (Objects.isNull(vitalSignMerge))
            return "4";
        if (vitalSignMerge.getStatus() == -1)
            return "4";
        return "0";
    }

    /**
     * 获取体征记录状态(3表合1)
     *
     * @param nurseRecordForm
     * @return
     */
    private String getTzjlzt3(NurseRecordForm nurseRecordForm) {
        if (Objects.isNull(nurseRecordForm))
            return "4";
        if (nurseRecordForm.getStatus() == -1)
            return "4";
        return "0";
    }

    /**
     * 获取体征值操作员信息
     *
     * @param vitalSignMerge
     * @param dmOrMc
     * @return
     */
    private String getCzyContent(VitalSignMerge vitalSignMerge, String dmOrMc) {

        if (Objects.isNull(vitalSignMerge))
            return "";
        Boolean isDm = StringUtils.equals(dmOrMc, "dm") ? true : false;
        if (StringUtils.isNotEmpty(vitalSignMerge.getOperatorCodeUpdate())) {
            return isDm ? vitalSignMerge.getOperatorCodeUpdate() : vitalSignMerge.getOperatorCodeUpdateName();
        }
        if (StringUtils.isNotEmpty(vitalSignMerge.getOperatorCode())) {
            return isDm ? vitalSignMerge.getOperatorCode() : vitalSignMerge.getOperatorName();
        }
        return "";
    }


    /**
     * 3表合1获取体征值操作员信息
     *
     * @param nurseRecordForm
     * @param dmOrMc
     * @return
     */
    private String getNurseRecordFormContent(NurseRecordForm nurseRecordForm, String dmOrMc) {

        if (Objects.isNull(nurseRecordForm))
            return "";
        Boolean isDm = StringUtils.equals(dmOrMc, "dm") ? true : false;
        if (StringUtils.isNotEmpty(nurseRecordForm.getOperatorCodeUpdate())) {
            return isDm ? nurseRecordForm.getOperatorCodeUpdate() : nurseRecordForm.getOperatorCodeUpdateName();
        }
        if (StringUtils.isNotEmpty(nurseRecordForm.getOperatorCode())) {
            return isDm ? nurseRecordForm.getOperatorCode() : nurseRecordForm.getOperatorName();
        }
        return "";
    }

    /**
     * 处理患者基本信息
     *
     * @param patient
     */
    public void handleDcIcuDatBrxxjlk(Patient patient) {
        errorIfEmpty(patient, "患者信息不存在");
        Map<String, Object> map = new HashMap<>();
        //map.put("jzlsh", patient.getVisitId());icuXh
        //修改为通过患者id检索信息
        map.put("icuXh", patient.getId());
        //DcIcuDatBrxxjlk dcIcuDatBrxxjlk=new DcIcuDatBrxxjlk();
        DcIcuDatBrxxjlk dcIcuDatBrxxjlk = dcIcuDatBrxxjlkDao.queryData(map);
        boolean isNewSave = Objects.isNull(dcIcuDatBrxxjlk) ? true : false;
        dcIcuDatBrxxjlk = setDcIcuDatBrxxjlk(patient, dcIcuDatBrxxjlk);
        System.out.println(dcIcuDatBrxxjlk.toString());
        try {
            if (isNewSave)
                dcIcuDatBrxxjlkDao.insert(dcIcuDatBrxxjlk);
            else
                dcIcuDatBrxxjlkDao.update(dcIcuDatBrxxjlk);
        }catch(Exception E){
            //失败患者
            logger.debug("处理数据中心 his 数据失败：患者住院号：" + patient.getName()+"--"+patient.getVisitId());
        }

        logger.debug("处理数据中心 his 数据成功：患者住院号：" + patient.getAppId());
    }

    /**
     * 赋值ICU 病人信息表
     */
    private DcIcuDatBrxxjlk setDcIcuDatBrxxjlk(Patient patient, DcIcuDatBrxxjlk dcIcuDatBrxxjlk) {
        errorIfEmpty(patient, "患者信息不存在");
        if (Objects.isNull(dcIcuDatBrxxjlk))
            dcIcuDatBrxxjlk = new DcIcuDatBrxxjlk();
        dcIcuDatBrxxjlk.setSjzt("");
        dcIcuDatBrxxjlk.setIcuXh(patient.getId());
        if (Objects.isNull(patient.getEnterTime()))
            dcIcuDatBrxxjlk.setRqtime(null);
        else
            dcIcuDatBrxxjlk.setRqtime(yyyyMMddHHmmssSdfToString(patient.getEnterTime())); // 入科时间

        if (Objects.nonNull(patient.getExitTime()))  // 出科时间
            dcIcuDatBrxxjlk.setCqtime(yyyyMMddHHmmssSdfToString(patient.getExitTime()));
        else
            dcIcuDatBrxxjlk.setCqtime("2999-12-31 00:000:00");
        dcIcuDatBrxxjlk.setJzlsh(patient.getVisitId());  // 就诊流水号
        dcIcuDatBrxxjlk.setYljgdm("40570021614040211A1001"); // 医院代码
        dcIcuDatBrxxjlk.setYljgmc("长治医学院附属和平医院"); // 医院名称
        dcIcuDatBrxxjlk.setZyhm(patient.getAppId()); // 住院号码
        dcIcuDatBrxxjlk.setMzh(""); // 门诊病历号（住院患者可以为空））
        dcIcuDatBrxxjlk.setPatid(patient.getAppId()); // 患者id 与住院号一致
        dcIcuDatBrxxjlk.setHzxm(patient.getName()); // 患者姓名
        dcIcuDatBrxxjlk.setJzlb("2"); // 就诊类别（重症为住院患者，所以就诊类别为2）
        dcIcuDatBrxxjlk.setKsdm("068");
        dcIcuDatBrxxjlk.setKsmc("重症医学科");
        dcIcuDatBrxxjlk.setBqdm("196745");
        dcIcuDatBrxxjlk.setBqmc("重症医学科护理站");
        dcIcuDatBrxxjlk = setZzysmc(dcIcuDatBrxxjlk, patient.getDoctorCode()); // 赋值主治医生代码和主治医生名称
        dcIcuDatBrxxjlk = setRkzddm(dcIcuDatBrxxjlk, patient.getId()); // 赋值诊断代码和诊断名称
        dcIcuDatBrxxjlk.setRkzdgrxxkbz("0"); // 入 ICU 诊断为感染性 休克患者标志 1 是，2 否，0 未知
        dcIcuDatBrxxjlk.setWc3hbundlebz("0"); // 3h 集 束 化 治 疗 （bundle）完成标志  1 是，2 否，0 未知
        dcIcuDatBrxxjlk.setWc6hbundlebz("0");
        dcIcuDatBrxxjlk.setDvtyfzlbz("0");
        dcIcuDatBrxxjlk.setQgcgpgbz(queryDrainageTubeRecord(patient.getId(), null));  // 患者气管插管标志
        dcIcuDatBrxxjlk.setFjhqgcgpgbz(queryDrainageTubeRecord(patient.getId(), 1));// 患者非计划气管插管拔管标志
        dcIcuDatBrxxjlk.setIsfjhcbg(queryDrainageTubeRecord(patient.getId(), 1));  // 患者icu非计划气管插管拔管标志
        dcIcuDatBrxxjlk.setIs3hjhh("0"); // 是否感染性休克 3h 集 束化治疗（bundle）完 成标志 1 是，2 否，0 未知
        dcIcuDatBrxxjlk.setIs6hjhh("0"); // 是否感染性休克 6h 集 束化治疗（bundle）完 成标志 1 是，2 否，0 未知
        dcIcuDatBrxxjlk.setIsicudvt("0"); // 是否 ICU 深静脉血栓 （DVT）预防标志 1 是，2 否，0 未知
        dcIcuDatBrxxjlk.setIsfjhcbg(queryDrainageTubeRecord(patient.getId(), 1)); // ICU 非计划气管插管 拔管标志 1 是，2 否，0 未知
        dcIcuDatBrxxjlk.setIs48hfjhcbg("0"); // ICU 气管插管拔管后 48h 内再插管 1 是，2 否，0 未知
        dcIcuDatBrxxjlk.setIsfjhzr(getIsfjhzr(patient.getUnplanned())); // 患者非计划转入标志
        dcIcuDatBrxxjlk.setCfdm(getCfdm(patient)); // 患者是否为48小时重返患者
        dcIcuDatBrxxjlk.setIshxjyf("0"); // 呼 吸 机 相 关 性 肺 炎 （VAP）的预防 1 是，2 否，0 未知
        dcIcuDatBrxxjlk.setIssyhxj(getIssyhxj(patient.getId()));  // 查询是否使用呼吸机
        if (StringUtils.equals(dcIcuDatBrxxjlk.getIssyhxj(), "1"))
            dcIcuDatBrxxjlk.setSyhxjts(getSyhxjts(patient.getId())); // 查询呼吸机使用天数
        else
            dcIcuDatBrxxjlk.setSyhxjts("0"); // 查询呼吸机使用天数
        dcIcuDatBrxxjlk.setSyhxjttts("0");   // 使用呼吸机抬头大于 30 度天数
        dcIcuDatBrxxjlk.setIssyhxjgr("0");   // 是否使用呼吸机感染
        dcIcuDatBrxxjlk.setIszxjmg("0");     // 是否使用中心静脉管
        dcIcuDatBrxxjlk.setZxjmgts("0");     // 中心静脉管天数
        dcIcuDatBrxxjlk.setIszxjmggr("0");   // 是否使用中心静脉管 感染
        dcIcuDatBrxxjlk.setIsdng("0");       // 是否使用导尿管
        dcIcuDatBrxxjlk.setIsdnggr("0");     // 是否使用导尿管感染
        dcIcuDatBrxxjlk.setIsyjsw("0");      // 是否预计病死
        dcIcuDatBrxxjlk.setIssw(Objects.isNull(patient.getDeathTime()) ? "2" : "1");  // 是否死亡
        dcIcuDatBrxxjlk.setIsyc("0"); // 是否压疮
        dcIcuDatBrxxjlk.setIsrgqdtc("0"); // 是否人工气道脱出
        dcIcuDatBrxxjlk.setApache("0");  // APACHE 评分
        dcIcuDatBrxxjlk.setGxrq(yyyyMMddHHmmssSdfToString(new Date()));
        dcIcuDatBrxxjlk.setSysId("0");
        if (StringUtils.equals(dcIcuDatBrxxjlk.getQgcgpgbz(), "1")) {
            dcIcuDatBrxxjlk.setQgcgsj(getQgcgsj(patient.getId(), null, "in"));
            dcIcuDatBrxxjlk.setQgbgsj(getQgcgsj(patient.getId(), null, "out"));
        } else {
            //给默认值
            dcIcuDatBrxxjlk.setQgcgsj("1900-01-01");
            dcIcuDatBrxxjlk.setQgbgsj("1900-01-01");
        }
        dcIcuDatBrxxjlk.setLsnid("1");
        if (StringUtils.equals(dcIcuDatBrxxjlk.getIsfjhcbg(), "1")) {
            dcIcuDatBrxxjlk.setFjhqgbgsj(getQgcgsj(patient.getId(), 1, "out"));
        } else {
            //给默认值
            dcIcuDatBrxxjlk.setFjhqgbgsj("1900-01-01");
        }
        dcIcuDatBrxxjlk.setQgcgbghzcgsj("1900-01-01");
        return dcIcuDatBrxxjlk;
    }

    /**
     * 气管插拔管时间
     *
     * @param patientId
     * @param planFlag
     * @return
     */
    private String getQgcgsj(String patientId, Integer planFlag, String inOrOut) {
        if (StringUtils.isEmpty(patientId)) {
            return null;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("patientId", patientId);
        if (Objects.nonNull(planFlag))
            map.put("planFlag", planFlag);
        List<DrainageTubeRecord> records = drainageTubeRecordDao.queryList(map);
        if (CollectionUtil.isEmpty(records) ||records.get(0)==null) {
            return null;
        }
        if (StringUtils.equals(inOrOut, "in") && records.get(0)!=null &&records.get(0).getIntubationTime()!=null)
            return yyyyMMddHHmmssSdfToString(records.get(0).getIntubationTime());
        if (StringUtils.equals(inOrOut, "out")&& records.get(0)!=null &&records.get(0).getTubeDrawingTime()!=null)
            return yyyyMMddHHmmssSdfToString(records.get(0).getTubeDrawingTime());
        return null;
    }

    /**
     * 获取使用呼吸机天数
     *
     * @return
     */
    private String getSyhxjts(String patientId) {
        if (StringUtils.isEmpty(patientId))
            return "0";
        VitalSignMerge vitalSignMerge = vitalSignMergeDao.findEarlyModeData(patientId);
        if (Objects.isNull(vitalSignMerge)) {
            return "0";
        }
        if (Objects.isNull(vitalSignMerge.getDataTime()))
            return "0";
        long time = new Date().getTime() - vitalSignMerge.getDataTime().getTime();
        return "" + time / 1000 / 60 / 60 / 24;
    }

    /**
     * 获取是否使用呼吸机
     *
     * @param patientId
     * @return
     */
    private String getIssyhxj(String patientId) {
        if (StringUtils.isEmpty(patientId))
            return "0";
        int isModeNum = vitalSignMergeDao.findIsModeNum(patientId);
        if (isModeNum > 0)
            return "1";
        return "2";
    }

    /**
     * 获取患者是否是24或48小时重返患者
     *
     * @param patient
     * @return
     */
    private String getCfdm(Patient patient) {
        if (Objects.isNull(patient)) {
            return "0";
        }
        //查询某个患者是否有入科记录，按入科时间倒叙
        List<Patient> outPatientList = patientDao.queryPatientByVisitIdAndFlag(patient.getVisitId(), "0");
        if (!CollectionUtil.isEmpty(outPatientList)) {
            Patient outPatient = outPatientList.get(0);
            //计算出当前入科时间是大于上次出科时间差值
            if (Objects.nonNull(patient.getEnterTime()) && Objects.nonNull(outPatient.getExitTime())) {
                long hour = (patient.getEnterTime().getTime() - outPatient.getExitTime().getTime()) / 1000 / 60 / 60;
                if (hour <= 24) {
                    return "1";
                }
                if (hour <= 48) {
                    return "2";
                }
            }
        }
        return "0";
    }


    private String getIsfjhzr(Integer unplanned) {
        if (Objects.isNull(unplanned))
            return "0";
        if (unplanned == 1)
            return "2";
        if (unplanned == 2)
            return "1";
        return "0";
    }


    /**
     * 获取患者插拔管数据
     *
     * @param patientId
     * @param planFlag
     * @return
     */
    private String queryDrainageTubeRecord(String patientId, Integer planFlag) {
        if (StringUtils.isEmpty(patientId)) {
            return "0";
        }
        Map<String, Object> map = new HashMap<>();
        map.put("patientId", patientId);
        if (Objects.nonNull(planFlag))
            map.put("planFlag", planFlag);
        int num = drainageTubeRecordDao.queryNum(map);
        if (num > 0)
            return "1";
        return "2";
    }


    /**
     * 赋值入icu诊断内容
     *
     * @param dcIcuDatBrxxjlk
     * @param patientId
     */
    private DcIcuDatBrxxjlk setRkzddm(DcIcuDatBrxxjlk dcIcuDatBrxxjlk, String patientId) {
        PatientDiagnosis patientDiagnosis = patientDiagnosisDao.queryDataByPatientId(patientId);
        if (Objects.isNull(patientDiagnosis)) {
            dcIcuDatBrxxjlk.setRkzddm("");
            dcIcuDatBrxxjlk.setRkzdmc("");
            return dcIcuDatBrxxjlk;
        }
        dcIcuDatBrxxjlk.setRkzddm(patientDiagnosis.getDiagnosisCode()==null?"":patientDiagnosis.getDiagnosisCode());
        dcIcuDatBrxxjlk.setRkzdmc(patientDiagnosis.getDiagnosisName()==null?"":patientDiagnosis.getDiagnosisName());
        return dcIcuDatBrxxjlk;
    }

    /**
     * 赋值主治医生信息
     *
     * @param dcIcuDatBrxxjlk
     * @param doctorCode
     */
    private DcIcuDatBrxxjlk setZzysmc(DcIcuDatBrxxjlk dcIcuDatBrxxjlk, String doctorCode) {
        if (StringUtils.isEmpty(doctorCode)) {
            dcIcuDatBrxxjlk.setZzysdm("");
            dcIcuDatBrxxjlk.setZzysmc("");
            return dcIcuDatBrxxjlk;
        }
        dcIcuDatBrxxjlk.setZzysdm(doctorCode);
        User user = userService.queryDataByCode(doctorCode);
        if (Objects.isNull(user))
            dcIcuDatBrxxjlk.setZzysmc("");
        else
            dcIcuDatBrxxjlk.setZzysmc(user.getUserName());
        return dcIcuDatBrxxjlk;
    }

    /**
     * 截取血压
     *
     * @param nbp
     * @return
     */
    private List<String> splitNbp(String nbp) {
        String systolicPressure = "";//收缩压
        String diastolicPressure = "";//舒张压
        if (StringUtils.isNotEmpty(nbp) && nbp.contains("/")) {
            String[] split = nbp.split("/");
            systolicPressure = split[0];
            diastolicPressure = split[1];
        }
        List<String> list = new ArrayList<String>();
        list.add(systolicPressure);
        list.add(diastolicPressure);
        return list;
    }
}
